package com.lyl.utils;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDateConverter implements Converter<String, Date> {

    private String format;

    public StringToDateConverter(String format) {
        this.format = format;
    }

    @Override
    public Date convert(String s) {// jsp    "2020/1/1"
        System.out.println("开始转换时间.....");
        try {
         return    new SimpleDateFormat(format).parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return  null;

    }
}
